package com.ykw.parking.controller;

import com.ykw.parking.Utils.Md5;
import com.ykw.parking.mapper.UserMapper;
import com.ykw.parking.pojo1.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class ChangePwdController {

    @RequestMapping("/changePwd")
    public String changePwd(){
        return "changePwd";
    }
    @Autowired
    UserMapper userMapper;

    @RequestMapping("/getNewPwd")
    @ResponseBody
    public String getNewPwd(String pwd, HttpSession session){
        String username =(String) session.getAttribute("username");
        User user = userMapper.queryUserbyname(username);
        String code = Md5.code(pwd);
        userMapper.updateUserPwd(code,user.getId());
        Subject subject = SecurityUtils.getSubject();
        subject.logout();
        return "设置成功";
    }
}
